package com.guchenbo.example.dubbo.template;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcException;

public abstract class InvokerTemplate<T> implements Invoker<T> {

  private Class<T> type;
  private URL url;

  public InvokerTemplate(Class type, URL url) {
    this.type = type;
    this.url = url;
  }

  @Override
  public Class getInterface() {
    return type;
  }

  @Override
  public Result invoke(Invocation invocation) throws RpcException {
    return doInvoke(invocation);
  }

  protected abstract Result doInvoke(Invocation invocation) throws RpcException;

  @Override
  public URL getUrl() {
    return url;
  }

  @Override
  public boolean isAvailable() {
    return true;
  }

  @Override
  public void destroy() {

  }
}
